<?php
namespace Home\Controller;

class IndexController extends HomeController {
    public function index(){ 
        $banner = M("Ad")->where(array('cid'=>7))->select();
        $this->assign('banner',$banner);

        $about = M("Onepage")->where(array('id'=>1))->find();
        $this->assign('about',$about);

        $Guideline = M("Onepage")->where(array('id'=>2))->find();
        $this->assign('Guideline',$Guideline);

        $map['show']=1;
        $map['index']=1;
        $obj = M('Goods');
        $list = $obj->where($map)->order('sort asc,id desc')->limit(6)->select();
        $this->assign('list',$list);


        unset($map);
        $map['path']=array("like","%0-11-%");
        $map['del'] = 0;
        $map['status'] = 1;
        $news=M("Article")->where($map)->order("createTime desc,id desc")->limit(6)->select();
        $this->assign("news",$news);
         
        $this->display();
    }

    public function search(){
        $keyword = I('key');

        if ($keyword=='') {
            $this->error('请输入查询条件');
        }

        if ($keyword!='') {
            /*$e=mb_detect_encoding($keyword, array('UTF-8', 'GBK'));
            if ($e!='UTF-8') {
                $keyword=mb_convert_encoding($keyword, "utf-8","gbk");
            }*/
            $map['title'] = array('like','%'.$keyword.'%');
        }

        $map['status'] = 1;
        $map['del'] = 0; 
        $obj = M('Article');
        $count = $obj->where($map)->count();
        import("Common.ORG.AmPage");
        $page = new \Page($count, 20);
        $show = $page->show();
        $list = $obj->where($map)->order('createTime desc')->limit($page->firstRow . ',' . $page->listRows)->select();
        $this->assign('list', $list);
        $this->assign('page', $show);

        $this->assign('keyword',$keyword);

        //设计师
        $obj = M('Designer');
        unset($map);
        $map['show'] = 1;
        $designer = $obj->where($map)->order('rand()')->limit(2)->select();
        foreach ($designer as $key => $value) {
            unset($map);
            $map['disID'] = $value['id'];
            $map['cid'] = 2;
            $designer[$key]['count'] = M('Feedback')->where($map)->count()+20;
        }
        $this->assign('designer',$designer);

        //案例
        $obj = M('Case');
        unset($map);
        $map['show'] = 1;
        $case = $obj->where($map)->order('rand()')->limit(1)->select();
        $this->assign('case',$case);

        //楼盘
        $obj = M('Property');
        unset($map);
        $map['show'] = 1;
        $property = $obj->where($map)->order('rand()')->limit(2)->select();
        foreach ($property as $key => $value) {
            unset($map);
            $map['disID'] = $value['id'];
            $map['cid'] = array('in',array(3,4));
            $property[$key]['count'] = M('Feedback')->where($map)->count()+40;
        }
        $this->assign('property',$property);

        $banner = M("Ad")->where(array('id'=>10))->find();
        $this->assign('banner',$banner);
        $this->display();
    }
}